package iplayparticle.view.controls;

import iplayparticle.view.controls.data.iplayparticlePanelData;
import particle.core.tools.PropertySet;
import particle.core.view.Renderer;
import particle.core.view.controls.Container;
import particle.core.view.controls.IControlData;
import particle.core.view.controls.IKeyEventHandler;
import particle.core.view.controls.KeyEvent;
import particle.core.view.controls.MotionEvent;
import state.GameGlobal;
import state.Key;

public class iplayparticlePanel extends Container implements IKeyEventHandler {
  // @BEGIN CHILD DECLARATIONS - This region was automatically generated, do not modify!

  // @END CHILD DECLARATIONS

  private iplayparticlePanelData m_controlData = null;

  public iplayparticlePanel() {
    m_controlData = new iplayparticlePanelData(this);
    getView().addKeyEventHandler(this);
    setPercentWidth(100);
    setPercentHeight(100);
  }

  public IControlData getControlData() {
    return m_controlData;
  }

  public void getDefaultProperties(PropertySet p_properties) {
    super.getDefaultProperties(p_properties);
    m_controlData.getDefaultProperties(p_properties);
  }
  
  public void drawPanel(Renderer renderer) {
    onDraw(renderer);
  }

  protected void onDraw(Renderer renderer) {
    super.onDraw(renderer);
    GameGlobal.systemCanvas.paint(renderer);
  }
  
  public void onKeyHandler(Object paramObject, KeyEvent keyEvent) {
    Key.modifiers = keyEvent.modifiers;
    if (keyEvent.type == KeyEvent.TypeDown) {
      GameGlobal.systemCanvas.keyPressed(keyEvent.key);
    } else if (keyEvent.type == KeyEvent.TypeUp) {
      GameGlobal.systemCanvas.keyReleased(keyEvent.key);
    }
    
  }

  protected void onMotion(MotionEvent motionEvent) {
    super.onMotion(motionEvent);
    if (motionEvent.type == MotionEvent.TypeUp) {
      GameGlobal.systemCanvas.pointerReleased(motionEvent.getX(), motionEvent.getY());
    } else if (motionEvent.type == MotionEvent.TypeDown) {
      GameGlobal.systemCanvas.pointerPressed(motionEvent.getX(), motionEvent.getY());
    } else if (motionEvent.type == MotionEvent.TypeMove) {
      GameGlobal.systemCanvas.pointerDragged(motionEvent.getX(), motionEvent.getY());
    }
  }

  protected void createChildren() {
    super.createChildren();
    m_controlData.createChildren();
  }

  protected void onDestroy() {
    super.onDestroy();
    m_controlData.destroyChildren();
  }
}
